package org.jheuristics.ga.operators.closures;

import java.util.Iterator;

import org.jheuristics.Individual;
import org.jheuristics.ga.DefaultPopulation;
import org.jheuristics.ga.GAConfig;
import org.jheuristics.ga.GAStatus;
import org.jheuristics.ga.Population;
import org.jheuristics.ga.operators.ClosureSelection;

/**
 * TODO
 *
 * @author Marcell Manfrin, marcell@ourgrid.org, Dec 13, 2005
 */
public class SetSelectionClosure implements ClosureSelection {

	/**
	 * TODO
	 *
	 * @param selected
	 * @param population
	 * @param status
	 * @param config
	 * @see org.jheuristics.ga.operators.ClosureSelection#execute(org.jheuristics.ga.Population, org.jheuristics.ga.Population, org.jheuristics.ga.GAStatus, org.jheuristics.ga.GAConfig)
	 */
	public void execute(Population selected, Population population, GAStatus status, GAConfig config) {
		Population toRemoval = new DefaultPopulation();
		for (Iterator it = selected.iterator(); it.hasNext(); ) {
			Individual individual = (Individual) it.next();
			if (population.contains(individual)) {
				toRemoval.addIndividual(individual);
			}
		}
		selected.removeIndividuals(toRemoval);
	}

}
